<?php
namespace app\www\controller;
use think\Db;
class Article
{
    public function recommend($id)
    {

        $sys = \app\common\model\Data::getSys();
        $ext = \app\common\model\Data::getExt();

        

        //推荐项目
        $article = Db::name('article')->where('id' , $id)->where('status',0)->select();

        $d = [

            'article'=> $article,
            'sys'  => $sys, 
            'ext'  => $ext,
        ];
        
        return view('',$d);


    } 


    public function article($id)
    {

        $sys = \app\common\model\Data::getSys();
        $ext = \app\common\model\Data::getExt();

        //分类导航
        $nav2 = Db::name('nav')->where('cat_id',2)->where('status',0)->order("sort desc,id desc")->select();
        $nav3 = Db::name('nav')->where('cat_id',3)->where('status',0)->order("sort desc,id desc")->select();

        //快捷文章分类
        $parent8 = Db::name('article_cat')->where('parent_id' , 8)->where('status',0)->order("sort desc,id desc")->select();

        foreach ($parent8 as $k => $v) {
            
            $parent = Db::name('article_cat')->where('parent_id' , $v['id'])->where('status',0)->order("sort desc,id desc")->select();        

            if($parent){
                foreach ($parent as $key => $value) {
                    $parent8[$k]['parent'] = $parent;
                }
            }

            if(!$parent){
                $parent8[$k]['parent'] = '';
            }

        }

        //文章
        $article = Db::name('article')->where('id' , $id)->where('status',0)->select();
        //分类
        $cat_title = Db::name('article_cat')->where('id' , $article['0']['cat_id'])->where('status',0)->select();

        //推荐
        $parent19 = Db::name('article')->where('cat_id' , 19)->order("sort desc,id desc")->where('status',0)->select();
        $cattitle = Db::name('article_cat')->where('id' , 19)->where('status',0)->select();

        //热门文章
        $rec1 = Db::name('article')->where('rec_id' , 1)->order("sort desc,id desc")->where('status',0)->select();
        $rec_title = Db::name('article_rec')->where('id' , 1)->where('status',0)->select();

        //首页右边第三
        $article21 = Db::name('article')->where('cat_id',21)->where('status',0)->order("sort desc,id desc")->limit(0,6)->select();
        $cat_title21 = Db::name('article_cat')->where('id',21)->where('status',0)->order("sort desc,id desc")->select();




        $d = [
            'nav2'      => $nav2,
            'nav3'      => $nav3,
            'parent8'   => $parent8,
            'article'   => $article,
            'cat_title' => $cat_title['0'],
            'rec1'      => $rec1,
            'rec_title' => $rec_title['0'],
            'parent19'  => $parent19,
            'cattitle'  => $cattitle,
            'article21' => $article21,
            'cat_title21'=>$cat_title21,
            'sys'  => $sys, 
            'ext'  => $ext,
        ];
        
        return view('',$d);


    } 
    







    
    //获取碎片，和系统配置
    public function demo(){
        $title = \app\common\model\Data::getSys("title");
        $index = \app\common\model\Data::getExt("index");
        
        t([$title,$index]);
    }
}
